package com.dxa.models.first;


import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.dxa.models.R;
import com.dxa.models.applog;

public class firstlayout extends Fragment{
	
	String TAG = "bottomlayout";
	
	private View view;
	private ImageView imageview;
	private ViewPager mPager;
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		
		applog.i(TAG, "firstlayout > onCreateView");
		
		view = inflater.inflate(R.layout.models_first, null);
		imageview = (ImageView) view.findViewById(R.id.loading);
		mPager = (ViewPager) view.findViewById(R.id.pager);
		mPager.setAdapter(new PagerAdapterClass(getActivity().getApplicationContext()));


		return view;
	}
	
	
	private class PagerAdapterClass extends PagerAdapter{
		private LayoutInflater mInflater;
		
		public PagerAdapterClass(Context mContext){
			super();
			mInflater = LayoutInflater.from(mContext);
		}
		
		@Override
		public int getCount() {
			// TODO Auto-generated method stub
			return 6;
		}

		@Override
		public Object instantiateItem(View pager, int position) {
			View v = null;
			SetLoadingImage(position);
    		v = mInflater.inflate(R.layout.models_first_gallery, null);
    		TextView tv = (TextView)v.findViewById(R.id.title0);
    		tv.setText("page : " + position);
    		((ViewPager)pager).addView(v, 0);
    		return v; 
		}
		
		@Override
		public void destroyItem(View pager, int position, Object view) {	
			((ViewPager)pager).removeView((View)view);
		}
		
		@Override
		public boolean isViewFromObject(View pager, Object obj) {
			return pager == obj; 
		}
		
		public void SetLoadingImage (int page){
			if (page == 0)
				imageview.setImageResource(R.drawable.gallery_loading_1);
			else if (page == 1)
				imageview.setImageResource(R.drawable.gallery_loading_2);
			else if (page == 2)
				imageview.setImageResource(R.drawable.gallery_loading_3);
			else if (page == 3)
				imageview.setImageResource(R.drawable.gallery_loading_4);
			else if (page == 4)
				imageview.setImageResource(R.drawable.gallery_loading_5);
			else if (page == 5)
				imageview.setImageResource(R.drawable.gallery_loading_6);
		}
	}
}

/*
import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.dxa.models.R;

public class firstlayout extends modelframelayout{
	
	private Context mContext; 
	private ImageView imageview;
	private ViewPager mPager;
	
	public firstlayout(Context context) 
	{
		super(context);
		mContext = context;
		inittoplayout();
	}

	public firstlayout(Context context, AttributeSet attrs) 
	{
		super(context, attrs);
		mContext = context;
		inittoplayout();
	}

    public void inittoplayout()
    {
        setLayout(R.layout.models_first);
		
		mPager = (ViewPager)findViewById(R.id.pager);
		mPager.setAdapter(new PagerAdapterClass(mContext));

		imageview = (ImageView) findViewById(R.id.loading);
		
    }
	
	private class PagerAdapterClass extends PagerAdapter{
		private LayoutInflater mInflater;
		
		public PagerAdapterClass(Context mContext){
			super();
			mInflater = LayoutInflater.from(mContext);
		}
		
		@Override
		public int getCount() {
			// TODO Auto-generated method stub
			return 6;
		}

		@Override
		public Object instantiateItem(View pager, int position) {
			View v = null;
			SetLoadingImage(position);
    		v = mInflater.inflate(R.layout.models_first_gallery, null);
    		TextView tv = (TextView)v.findViewById(R.id.title0);
    		tv.setText("page : " + position);
    		((ViewPager)pager).addView(v, 0);
    		return v; 
		}
		
		@Override
		public void destroyItem(View pager, int position, Object view) {	
			((ViewPager)pager).removeView((View)view);
		}
		
		@Override
		public boolean isViewFromObject(View pager, Object obj) {
			return pager == obj; 
		}
		
		public void SetLoadingImage (int page){
			if (page == 0)
				imageview.setImageResource(R.drawable.gallery_loading_1);
			else if (page == 1)
				imageview.setImageResource(R.drawable.gallery_loading_2);
			else if (page == 2)
				imageview.setImageResource(R.drawable.gallery_loading_3);
			else if (page == 3)
				imageview.setImageResource(R.drawable.gallery_loading_4);
			else if (page == 4)
				imageview.setImageResource(R.drawable.gallery_loading_5);
			else if (page == 5)
				imageview.setImageResource(R.drawable.gallery_loading_6);
		}
	}
}
*/
